package reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * 使用反射机制调用Student的有参构造器实例化
 */
public class Test {
    public static void main(String[] args) {
        try {
            Class clazz = Class.forName("reflect.Student");
            Constructor constructor = clazz.getConstructor(String.class, int.class, char.class);
            Object student = constructor.newInstance("张三", 18, '男');
            System.out.println(student);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
}
